package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.MonitorFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/8/5.
 */
@Controller
@RequestMapping("/rds_monitorFault")
public class MonitorFaultController {
    @Resource
    private MonitorFaultService monitorFaultService;

    @RequestMapping(value = "/getMonitorReportFault4DT")
    @ResponseBody
    public DTResponseDto getMonitorReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = monitorFaultService.getMonitorReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/updateMonitorFault")
    @ResponseBody
    public JsonMsgDto updateMonitorFault(Integer monitorFaultId, Integer monitorFaultLevel, Integer monitorFaultType, String monitorFaultPhoto, String monitorFaultReason, Double monitorMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(monitorFaultService.updateMonitorFault(monitorFaultId, monitorFaultLevel, monitorFaultType, monitorFaultPhoto, monitorFaultReason, monitorMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteMonitorFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteMonitorFaultByIds(String monitorFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(monitorFaultService.deleteMonitorFaultByIds(monitorFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMonitorCoordinate4Map")
    @ResponseBody
    public JsonMsgDto getMonitorCoordinate4Map(Integer orgId, Integer actorId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(monitorFaultService.getMonitorCoordinate4Map(orgId, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMonitorEnergyByXY")
    @ResponseBody
    public JsonMsgDto getMonitorEnergyByXY(String longitude, String latitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(monitorFaultService.getMonitorEnergyByXY(longitude, latitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/reportMonitorFault")
    @ResponseBody
    public JsonMsgDto reportMonitorFault(Integer monitorId, Integer monitorFaultCreatorId, Integer monitorFaultLevel, Integer monitorFaultType,
                                         String monitorFaultPhoto, String monitorFaultReason, Double monitorMoney, Integer monitorOrgId, Integer monitorMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            monitorFaultService.reportMonitorFault(monitorId, monitorFaultCreatorId, monitorFaultLevel, monitorFaultType,
                    monitorFaultPhoto, monitorFaultReason, monitorMoney, monitorOrgId, monitorMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMonitorFaultIsReport")
    @ResponseBody
    public JsonMsgDto getMonitorFaultIsReport(Integer monitorId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(monitorFaultService.getMonitorFaultIsReport(monitorId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getMonitorFaultReport4DT")
    @ResponseBody
    public DTResponseDto getMonitorFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId,String roadName, String startRoad, String endRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = monitorFaultService.getMonitorFaultReport4DT(dtRequestDto, actorId, orgId, roadName, startRoad, endRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

}
